#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsScene>
#include <QRawFont>
#include "graphicssubclass.h"
#include "pathsubclass.h"
#include "scenesubclass.h"
#include "math.h"
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    void rect_moved_useful_2(qreal xCord, qreal yCord, int index, int pathNo, int pathType);
//    void orphan_rect_moved_useful_2(qreal xCord, qreal yCord,int pathNo, int pathType,QPointF myPos);
private slots:
    void on_actionDraw_line_triggered();

    void drawLine(QPoint *p0, QPoint *p1);
    void drawRect(QPoint *p0, QPoint *p1);
    void drawCubicBezier(QPoint *p0, QPoint *p1,QPoint *p2, QPoint *p3);
    void slot_addRectsToScene(int myNo,int myType);
    void slot_removeRectsFromScene(int myNo,int myType);
    void slot_addControlRectsToScene(int myNo,int myType);
    void slot_removeControlRectsFromScene(int myNo,int myType);
    void on_actionDraw_cubic_bezier_triggered();
    void on_actionIntersect_triggered();
    void on_pushButton_2_clicked();
    void on_pushButton_5_clicked();
    void on_actionUndo_remove_triggered();
    void on_actionRemove_item_s_triggered();
    void on_actionItem_list_triggered();
    void on_actionDraw_offset_bezier_triggered();
    void on_actionNo_of_selected_Items_triggered();
    void on_pushButton_clicked();
    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_6_clicked();

    void on_pushButton_7_clicked();

    void on_actionOpen_Font_triggered();

    void on_actionPNG_file_triggered();

    void on_pushButton_8_clicked();



    void on_pushButton_9_clicked();

    void on_actionShow_Grid_triggered();

private:
    Ui::MainWindow *ui;
//    GraphicsSubClass *myView;
    sceneSubClass *myScene;

    void lineDrawing(QPoint *p0, QPoint *p1, int lineStatus, int itemNo, int pathType);
    pathSubClass *myLineItem;
    int noOfLines;

    void rectDrawing(QPoint *p0, QPoint *p1);
    pathSubClass *myRecItem;
    int noOfRects;

    void bezierDrawing(QPoint *p0, QPoint *p1,QPoint *p2, QPoint *p3, int bezierStatus, int pathType, int itemNo);
    pathSubClass *myBezierItem;
    int noOfBeziers;
    QMap<int, pathSubClass* > orp_LineItems;
    QMap<int, pathSubClass* > orp_BezierItems;

    QList<QGraphicsItem *> selItemList;
    int noOfSelectedItems;

    void calIntersect();
    void intersectTwoLines(pathSubClass *item1, pathSubClass *item2);
//    QPointF *intersectPoints[10];

    QMap<int,pathSubClass* > delItemMap;
    QMap<int,QPointF > delItemPosMap;
    int delCount;

    void calOffset();
    QLineF *offsetPath(QPointF *myp0, QPointF *myp1, double offset);
    QPointF *offsetPoints[2];

    void calBzrOffset();
    QLineF *linesArray[3];
    void calIntersectPointsForBzr();
    QPointF *intersectPoints[10];

    void setStatusBarValues(QString msg, int timeOut);
//-------------------------------------------------------------------------function part
//-------------------------------------------------------------------------function part
    QRawFont *myFont;
    QString fontFileName;
    void initiateFont();
    qreal myascent;
    QPainterPath basePath;
    void initiateBasePath();


    QPainterPath *basePath_1, *drawFont_path;
    int elementCount;
    QPointF *controlPoints[100];
    int noOfControlPoints;
    QPointF *drawFont_points[200];
    QPointF *temp_points[200];
    void drawFont_function();

    void drawOrgFont();
    void showPointArray(QPointF *myArray[]);

    void drawTempPath();
    pathSubClass pathSubItem1;
    QPainterPath *arrOfPath[10];
    pathSubClass *arrOfPathItems[10];

    QMap<int, pathSubClass* > curvePathItems;
    QMap<int, pathSubClass* > LinePathItems;
    QMap<int, pathSubClass* > allPathItems;
    QMap<int, rectSubClass* > controlRects;
    int noOfControlRects;
    void setControlRects();
    void drawControlPoints(QPointF *point1,QPointF *point2,QPointF *pointC1, QPointF *pointC2,pathSubClass *item1, int pathNo, int pathType);
    void redrawControlPoints(qreal xCord, qreal yCord, int index, int pathNo, int pathType);
//    void orphan_redrawControlPoints( qreal xCord, qreal yCord, int pathNo, int pathType, QPointF myPos);
    //----------------------------------------------------------------------------------
    void saveImageAsPng();
    void scaleMyCurve(pathSubClass *item1,double value);
};

#endif // MAINWINDOW_H
